﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DTO;
using DAO;
namespace QLDaiLy
{
    public partial class DanhSachPhieuXuat : XtraUserControl
    {
        public DanhSachPhieuXuat()
        {
            InitializeComponent();
            LoadDanhDanhSachPhieuXuat();
        }
        private void LoadDanhDanhSachPhieuXuat()
        {

            List<PhieuXuatDTO> list = new List<PhieuXuatDTO>();
            list = PhieuXuatDAO.LoadDanhDanhSachPhieuXuat();
            gridPhieuXuatControl.DataSource = list;
        }
        private void gridViewDanhSach_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
        {
            if (e.IsGetData)
            {
                e.Value = QLDaiLy.Properties.Resources.delete;
            }
        }

        private void repositoryItemPictureDelete_Click(object sender, EventArgs e)
        {
             MessageBox.Show("Bạn muốn xoá hay không ?", "Thông báo", MessageBoxButtons.OKCancel);
            string MaPhieuXuat = gridViewDanhSach.GetRowCellValue(gridViewDanhSach.FocusedRowHandle, gridViewDanhSach.Columns["MaPhieuXuat"]).ToString();
            string TongGiaTri = gridViewDanhSach.GetRowCellValue(gridViewDanhSach.FocusedRowHandle, gridViewDanhSach.Columns["TongGiaTri"]).ToString();
            int TongTriGia = int.Parse(TongGiaTri);
            string MaDaiLy = gridViewDanhSach.GetRowCellValue(gridViewDanhSach.FocusedRowHandle, gridViewDanhSach.Columns["MaDaiLy"]).ToString();
            bool kq= ChiTietPhieuXuatDAO.deleteListCTPX(MaPhieuXuat);
            if (kq == true)
            {
                if (PhieuXuatDAO.deletePhieuXuat(MaPhieuXuat))
                {
                    // MessageBox.Show("Xoá thành công");
                    bool kqcapNhatGia = DaiLyDAO.CapNhatGiaTien(MaDaiLy, TongTriGia);
                    if (kqcapNhatGia)
                    {
                        LoadDanhDanhSachPhieuXuat();
                    }
                    else
                    {
                        MessageBox.Show("GiaTiền chưa được cập nhật");
                    }
                }
                else
                {
                    MessageBox.Show("Xoá thành thất bại");
                }
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

     }
    
}
